package com.blank.net.Interceptor;

import android.os.Build;

import com.blank.net.config.NetConfig;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author: blank
 * @date : 2022/5/18
 * @desc : 请求头拦截器
 * @url : https://gitee.com/hyx_blank
 */
public class HttpHeaderInterceptor implements Interceptor {

    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
//        lang zh_CN或者en_US
        String lang = "";
        //  配置请求头
        String tokenType = "tokenType";
        Request request = chain.request();
        Request.Builder builder = request.newBuilder()
//                 .header("app_key", "appId")
//                .header("appid", Constant.APP_ID)
                .header("token", NetConfig.Companion.getToken())
                .header("Content-Type", "application/json")
//                .header("lang", lang)
//                .header("BuildVersion", String.valueOf(Utils.getVersionCode(App.getInstance())))
//                .addHeader("Connection", "close")
//                .addHeader("Accept-Encoding", "identity")
                ;
        if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
            builder.addHeader("Connection", "close");
        }
        request = builder.build();
        return chain.proceed(request);
    }
}
